using MultiAgentsClient.ChatDataStructures;
using MultiAgentsServer.Scripts.Shared;
#if BACKEND
using static MultiAgentsServer.Scripts.Shared.ModelConsts;
using MultiAgentsServer.Scripts.Database;
#endif

namespace MultiAgentsShared;

public class AgentTemplate : SerializableObjectBase
{
    public int Id { get; set; }
    public string Name { get; set; } = NameConsts.DefaultAgentName;
    public int UserId { get; set; }
    public string LlmModel { get; set; } = NameConsts.DefaultModelName;
    public float Temperature { get; set; }
    public List<string> AllowedTools { get; set; } = [];
    public string PresetMessage { get; set; } = "";

    public AgentTemplate()
    {
    }

    public AgentTemplate(int id, string name, int userId, string llmModel, float temperature, List<string> allowedTools, string presetMessage)
    {
        Id = id;
        Name = name;
        UserId = userId;
        LlmModel = llmModel;
        Temperature = temperature;
        AllowedTools = allowedTools;
        PresetMessage = presetMessage;
    }

#if FRONTEND
    public AgentDisp ToDisp()
    {
        return new AgentDisp(Id, Name, false);
    }
#endif

#if BACKEND
    public AgentTemplateDB ToDb()
    {
        return new AgentTemplateDB()
        {
            Id = Id,
            Name = Name,
            UserId = UserId,
            LLMModel = LlmModel,
            Temperature = Temperature,
            AllowedTools = AllowedTools,
            PresetMessage = PresetMessage,
        };
    }

    public static AgentTemplate GetInitialAgent()
    {
        return new AgentTemplate()
        {
            Id = 0,
            Name = NameConsts.NewAgentName,
            UserId = -1,
            LlmModel = LlmModels.Gpt_4o_mini.ToString(),
            Temperature = 1,
            AllowedTools = [],
            PresetMessage = "[]",
        };
    }
#endif
}
